package com.jr.mapper;

import com.jr.pojo.ServiceType;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface ServiceTypeMapper {

    @Select("SELECT * FROM service_types WHERE service_type_id = #{serviceTypeId}")
    ServiceType selectById(Integer serviceTypeId);

    @Select("SELECT * FROM service_types WHERE is_active = true")
    List<ServiceType> selectActive();

    @Select("SELECT * FROM service_types")
    List<ServiceType> selectAll();

    @Insert("INSERT INTO service_types (name, description, base_price, price_unit, is_active, created_at) " +
            "VALUES (#{name}, #{description}, #{basePrice}, #{priceUnit}, #{isActive}, #{createdAt})")
    @Options(useGeneratedKeys = true, keyProperty = "serviceTypeId")
    int insertServiceType(ServiceType serviceType);

    @Update("UPDATE service_types SET name=#{name}, description=#{description}, base_price=#{basePrice}, " +
            "price_unit=#{priceUnit}, is_active=#{isActive} WHERE service_type_id=#{serviceTypeId}")
    int updateServiceType(ServiceType serviceType);

    @Update("UPDATE service_types SET is_active = #{isActive} WHERE service_type_id = #{serviceTypeId}")
    int updateStatus(@Param("serviceTypeId") Integer serviceTypeId, @Param("isActive") Boolean isActive);
}
